package com.yy.wga.mp.module.promoter.controller;


import com.yy.wga.mp.common.aop.NotLogin;
import com.yy.wga.mp.module.promoter.manager.PromoterManager;
import com.yy.wga.mp.module.promoter.request.SharerProductSetCommissionReq;
import com.yy.wga.mp.module.promoter.request.SharerSetCommissionReq;
import com.yy.wga.mp.module.promoter.response.PromoterStatusResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("api/promoter")
@Slf4j
@Api(tags = "推客管理")
public class PromoterController {

    @Resource
    private PromoterManager promoterManager;

    /**
     * 获取推客状态
     *
     * @param openId
     */
    @ApiOperation(value = "获取推客状态")
    @GetMapping("/getPromoterStatus")
    public Result<PromoterStatusResp> getPromoterStatus(@RequestParam("openId") String openId) {
        return Result.success(promoterManager.getPromoterStatus(openId));
    }

    @NotLogin
    @GetMapping("/bindCallBack")
    public String callBack(String callBackStr) {
        log.info("绑定回调信息:{}", callBackStr);
        // TODO 需要对接的话，可以将用户落户 之后不需要调用getPromoterStatus方法判断
        return "success";
    }


    /**
     * 设置推客佣金
     *
     * @param req req
     * @return void
     */
    @ApiOperation(value = "设置推客佣金")
    @PostMapping("/setSharerCommission")
    public Result<Void> setSharerCommission(@RequestBody @Valid SharerSetCommissionReq req) {
        promoterManager.setSharerCommission(req);
        return Result.success();
    }

    /**
     * 设置推客单个商品佣金
     *
     * @param req req
     * @return void
     */
    @ApiOperation(value = "设置推客单个商品佣金")
    @PostMapping("/setSharerProductCommission")
    public Result<Void> setSharerProductCommission(@RequestBody @Valid SharerProductSetCommissionReq req) {
        promoterManager.setSharerProductCommission(req);
        return Result.success();
    }

    /**
     * 获取推客单个商品佣金
     *
     * @param spuId spuId
     * @return void
     */
    @ApiOperation(value = "获取推客单个商品佣金")
    @PostMapping("/getSharerProductCommission")
    public Result<Integer> getSharerProductCommission(@RequestParam("spuId") String spuId) {
        return Result.success(promoterManager.getSharerProductCommission(spuId));
    }


}
